Skip to content

KAFKA-7006 - remove duplicate Scala ResourceNameType in preference to…#5152

Merged
junrao merged 5 commits intoapache:trunkfrom
big-andy-coates:drop_scala_resource_name_type
Jun 8, 2018
Merged

KAFKA-7006 - remove duplicate Scala ResourceNameType in preference to…#5152
junrao merged 5 commits intoapache:trunkfrom
big-andy-coates:drop_scala_resource_name_type

Conversation

@big-andy-coates
Copy link
Contributor

@big-andy-coates big-andy-coates commented Jun 6, 2018

remove duplicate Scala ResourceNameType in preference to in preference to Java ResourceNameType.

See KAFKA-7006.

This is follow on work for KIP-290 and PR #5117, which saw the Scala ResourceNameType class introduced.

I've added tests to ensure AclBindings can't be created with ResourceNameType.ANY or UNKNOWN.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@junrao, @cmccabe - this is a follow on PR for KIP-290.

@Test
public void testMatching() throws Exception {
assertTrue(ACL1.equals(ACL1));
public void testMatching() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took the opportunity to fix the compiler warnings in this test file, as the PR was small...

…ill never have ResourceNameType.ANY or UNKNOWN.
@ijuma
Copy link
Member

ijuma commented Jun 7, 2018

cc @cmccabe

@big-andy-coates
Copy link
Contributor Author

test this please

…ssages from newer clients to get to the right part of KafkaApis.java
Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@big-andy-coates : Thanks for the patch. LGTM. A couple of minor comments below.

*
* @param resource the resource path to which the acls belong.
* the supplied resource will have a specific resource name type,
* i.e. the resource name type will not be ``ResourceNameType.ANY`` or ``ResourceNameType.UNKNOWN``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this true? I thought the current implementation allows you to pass in ResourceNameType.ANY to retrieve ACLs specified on either LITERAL or PREFIX?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is true. SimpleAclAuthorizer expects a concrete Resource, not something which could match multiple resources. The code is here:

  override def removeAcls(resource: Resource): Boolean = {
    inWriteLock(lock) {
      val result = zkClient.deleteResource(resource)
      updateCache(resource, VersionedAcls(Set(), 0))
      updateAclChangedFlag(resource)
      result
    }
  }

The messiness here is that this constraint is not expressed in the type system. We use the same enum to describe the name types a concrete resource can have vs. a resource filter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. The enum has ANY and UNKNOWN values, but the code won't allow them to be passed to the authorizer. I documented so that people implementing their own would know they aren't going to get these values. It's part of the downside to standardizing on the Java ResourceNameType.


def getMatchingAcls(resourceType: ResourceType, resourceName: String): Set[Acl] = {
val filter = new ResourceFilter(resourceType.toJava, resourceName, JResourceNameType.ANY)
val filter = new ResourceFilter(resourceType.toJava, resourceName, ResourceNameType.ANY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already removed in another PR...

case Prefixed => "/kafka-prefixed-acl"
case ResourceNameType.LITERAL => "/kafka-acl"
case ResourceNameType.PREFIXED => "/kafka-prefixed-acl"
case _ => throw new IllegalArgumentException("Unknown name type:" + nameType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to say "invalid name type" since rather than "Unknown name type", since the name type may not be UNKNOWN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, (but in an up coming PR)

case Prefixed => "/kafka-prefixed-acl-changes"
case ResourceNameType.LITERAL => "/kafka-acl-changes"
case ResourceNameType.PREFIXED => "/kafka-prefixed-acl-changes"
case _ => throw new IllegalArgumentException("Unknown name type:" + nameType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to say "invalid name type" since rather than "Unknown name type", since the name type may not be UNKNOWN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in an upcoming PR.

@cmccabe
Copy link
Contributor

cmccabe commented Jun 7, 2018

+1. LGTM after the posted small changes are made

@big-andy-coates
Copy link
Contributor Author

@cmccabe @junrao - thanks for reviews!

(Unrelated test failure...)

This looks good to merge, (assuming you're happy that the minor points raised are addressed in other PRs?).

However, I'd prefer my other PR, (#5160), to be merged first, if at all possible, as there will be conflicts and I'd rather resolve in this PR.

@big-andy-coates
Copy link
Contributor Author

test this please

# Conflicts:
#	clients/src/main/java/org/apache/kafka/common/acl/AclBinding.java
#	core/src/main/scala/kafka/admin/AclCommand.scala
#	core/src/main/scala/kafka/security/SecurityUtils.scala
#	core/src/main/scala/kafka/security/auth/Resource.scala
#	core/src/main/scala/kafka/security/auth/SimpleAclAuthorizer.scala
#	core/src/main/scala/kafka/server/KafkaApis.scala
#	core/src/test/scala/integration/kafka/api/AuthorizerIntegrationTest.scala
@big-andy-coates
Copy link
Contributor Author

@ijuma / @junrao, merged in trunk. Should be good to merge this now. Thanks!

@junrao junrao merged commit 0b3989f into apache:trunk Jun 8, 2018
junrao pushed a commit that referenced this pull request Jun 8, 2018
#5152)

remove duplicate Scala ResourceNameType in preference to in preference to Java ResourceNameType.

This is follow on work for KIP-290 and PR #5117, which saw the Scala ResourceNameType class introduced.

I've added tests to ensure AclBindings can't be created with ResourceNameType.ANY or UNKNOWN.

Reviewers: Colin Patrick McCabe <colin@cmccabe.xyz>, Jun Rao <junrao@gmail.com>
@big-andy-coates big-andy-coates deleted the drop_scala_resource_name_type branch June 8, 2018 20:48
ying-zheng pushed a commit to ying-zheng/kafka that referenced this pull request Jul 6, 2018
apache#5152)

remove duplicate Scala ResourceNameType in preference to in preference to Java ResourceNameType.

This is follow on work for KIP-290 and PR apache#5117, which saw the Scala ResourceNameType class introduced.

I've added tests to ensure AclBindings can't be created with ResourceNameType.ANY or UNKNOWN.

Reviewers: Colin Patrick McCabe <colin@cmccabe.xyz>, Jun Rao <junrao@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants